COPYDATASTRUCT (Structures)
Last changed: shipr on StackOverflow-76.14.214.109

.
Summary
TODO - a short description

C# Definition:

[StructLayout(LayoutKind.Sequential)]
struct COPYDATASTRUCT
{
    public IntPtr dwData;
    public int cbData;
    public IntPtr lpData;
}

const int WM_COPYDATA = 0x004A;

VB.NET Definition:

<StructLayout(LayoutKind.Sequential)> _
Structure COPYDATASTRUCT
   Public dwData As IntPtr
   Public cdData As Integer
   Public lpData As IntPtr
End Structure

User-Defined Field Types:

None.

Documentation

      public static IntPtr IntPtrAlloc<T>(T param)
      {
     IntPtr retval = Marshal.AllocHGlobal(Marshal.SizeOf(param));
     Marshal.StructureToPtr(param, retval, false);
     return (retval);
      }

      public static void IntPtrFree(IntPtr preAllocated)
      {
     if (IntPtr.Zero == preAllocated) throw (new Exception("Go Home"));
    Marshal.FreeHGlobal(preAllocated); preAllocated = IntPtr.Zero;
      }

      [StructLayout(LayoutKind.Sequential)]
      struct COPYDATASTRUCT
      {
     public UInt32 dwData;
     public int cbData;
     public IntPtr lpData;
      }

     IntPtr buffer = IntPtrAlloc(txStruct);
     COPYDATASTRUCT copyData = new COPYDATASTRUCT();
     copyData.dwData = 0xC0b1;
     copyData.lpData = buffer;
     copyData.cbData = Marshal.SizeOf(txStruct);
     IntPtr copyDataBuff= IntPtrAlloc(copyData);
     SendMessage(hWnd, WM_COPYDATA, copyDataBuff, IntPtr.Zero);
     IntPtrFree(copyDataBuff); copyDataBuff = IntPtr.Zero;
     IntPtrFree(buffer); buffer = IntPtr.Zero;